﻿package mortal.game.view.medal.view
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.medal.*;
    import mortal.mvc.core.*;

    public class MedalBigIcon extends ToolTipSprite
    {
        private var _tmedal:TMedal;
        private var _item:BaseItem;
        private var _bg:GImageBitmap;
        private var _medalLvIcon:GImageBitmap;
        private var _medalLevel:BitmapNumberText;
        private var _selectEffect:SWFPlayer;
        public var isOpenWin:Boolean = true;

        public function MedalBigIcon()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseChildren = false;
            this.mouseEnabled = true;
            this.buttonMode = true;
            this._bg = UIFactory.gImageBitmap(ImagesConst.playerMedalBg, 0, 0, this, this.resetPos);
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this._item.setSize(66, 71);
            var _loc_1:Boolean = false;
            this._item.mouseEnabled = false;
            this._item.mouseChildren = _loc_1;
            var _loc_1:Boolean = false;
            this._item.isDropAble = false;
            this._item.isDragAble = _loc_1;
            this._item.isShowLock = false;
            this.addChild(this._item);
            this._medalLvIcon = UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_11, 33, 75, this);
            this._medalLevel = UIFactory.bitmapNumberText(60, 76, "FightInfoNum.png", 12, 15, -1, this);
            this.configEventListener(MouseEvent.CLICK, this.openMedal);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._bg = null;
            this._item.dispose(param1);
            this._item = null;
            this._medalLvIcon.dispose(param1);
            this._medalLvIcon = null;
            this._medalLevel.dispose(param1);
            this._medalLevel = null;
            if (this._selectEffect)
            {
                this._selectEffect.dispose(param1);
                this._selectEffect = null;
            }
            this._tmedal = null;
            this.isOpenWin = true;
            super.disposeImpl(param1);
            return;
        }// end function

        private function resetPos() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            this._item.x = (this._bg.width - this._item.width >> 1) - 3;
            this._item.y = (this._bg.height - this._item.height >> 1) - 7;
            return;
        }// end function

        private function openMedal(event:MouseEvent) : void
        {
            if (this.isOpenWin)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MedalOpen));
            }
            return;
        }// end function

        public function showEffect(param1:Boolean, param2:Number = 0, param3:Number = 0, param4:String = "medalPlayerModuleEffect.swf") : void
        {
            if (param1)
            {
                if (this._selectEffect == null)
                {
                    this._selectEffect = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                    this._selectEffect.timeRate = 3;
                    this._selectEffect.load(param4, ModelType.NormalSwf, null);
                }
                this._selectEffect.move(param2, param3);
                this.addChild(this._selectEffect);
            }
            else if (this._selectEffect)
            {
                DisplayUtil.removeMe(this._selectEffect);
            }
            return;
        }// end function

        public function set medal(param1:TMedal) : void
        {
            this._tmedal = param1;
            if (this._tmedal)
            {
                this._item.source = MedalUtil.getMedalIconUrlByTmedal(this._tmedal, 1);
                this._item.toolTipData = this._tmedal;
                this._medalLevel.text = "" + this._tmedal.typeLevel;
                this._medalLvIcon.visible = true;
                this.filters = [];
                this.showEffect(true, 52, 55);
            }
            else
            {
                this._item.source = MedalUtil.getMedalIconUrlByTmedal(null, 1);
                this._item.toolTipData = null;
                this._medalLevel.text = "";
                this._medalLvIcon.visible = false;
                this.filters = [FilterConst.colorFilter2];
                this.showEffect(false);
            }
            return;
        }// end function

    }
}
